package com.pml.filter;


import com.sun.deploy.net.HttpRequest;
import com.sun.deploy.net.HttpResponse;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SimpleFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("SimpleFilterinit"+filterConfig.getInitParameter("ref"));
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("执行之前");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        servletRequest.setAttribute("hh","你好");
//        filterChain.doFilter(servletRequest,servletResponse);
        HttpServletRequest request=(HttpServletRequest)servletRequest;
        HttpServletResponse response=(HttpServletResponse)servletResponse;
        response.sendRedirect("test.jsp");
//        request.getRequestDispatcher("test.jsp").forward(request,response);
        System.out.println("执行之后");
    }

    @Override
    public void destroy() {
        System.out.println("执行销毁");
    }
}
